package com.example.sharding.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.example.sharding.dao.TAnnotationStudentMapper;
import com.example.sharding.enerty.TAnnotationStudent;
import com.example.sharding.service.TAnnotationStudentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @program: test_demo
 * @description: 数据字典业务层
 * @author: yanghua
 * @create: 2021-11-04 19:57
 **/
@Service
public class TAnnotationStudentServiceImpl extends ServiceImpl<TAnnotationStudentMapper, TAnnotationStudent> implements TAnnotationStudentService {

    @Resource
    private TAnnotationStudentMapper tannotationStudentMapper;

    @Override
    public IPage<TAnnotationStudent> listPager(TAnnotationStudent student) {
        LambdaQueryWrapper<TAnnotationStudent> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StrUtil.isNotEmpty(student.getName()),TAnnotationStudent::getName,student.getName());
        queryWrapper.orderByAsc(TAnnotationStudent::getName);
        Page<TAnnotationStudent> page = new Page<>(student.getCurrPage(),student.getPageSize());
        IPage<TAnnotationStudent> selectPage = tannotationStudentMapper.selectPage(page, queryWrapper);
        return selectPage;
    }

    @Override
    public R<TAnnotationStudent> single(TAnnotationStudent student) {
//        if (true){
//            throw new RuntimeException("我异常了");
//        }
        LambdaQueryWrapper<TAnnotationStudent> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TAnnotationStudent::getName,student.getName());
        return R.ok(tannotationStudentMapper.selectOne(queryWrapper));
    }
}
